package cn.hnver.xiaohui;
import java.util.ArrayList;
import java.util.Scanner;

public class KTVByArrayList {
	public class KTVByArraayList {
		public void main(String[] args) {
			System.out.println("------欢迎来到点歌系统------");
			System.out.println("0.添加歌曲至列表");
			System.out.println("1.将歌曲置顶");
			System.out.println("2.将歌曲前移一位");
			System.out.println("3.退出");
			ArrayList lineUpList =new ArrayList();
			addMusicList (lineUpList);
			while (true) {
				System.out.println("输入要执行的操作序号；");
				Scanner scanner =new Scanner(System.in);
				int command =scanner.nextInt();
				switch (command) {
				case 0:
					addMusicList(lineUpList);
					break;
				case 1:
					setTop(lineUpList);
					break;
				case 2:
					setBefore(lineUpList);
					break;
					case 3:
						exit();
						break;
				default:
					System.out.println("-------------");
					System.out.println("功能选择有误，请输入正确的功能序号！");
					break;
				}
				System.out.println("当前歌曲列表："+lineUpList);
			}
		}

		private void exit() {
			// TODO Auto-generated method stub
			System.out.println("------退出-------");
			System.out.println("您已退出系统");
			System.out.println(0);
		}

		private void addMusicList(ArrayList lineUpList) {
			// TODO Auto-generated method stub
			lineUpList.add("一万次悲伤");
			lineUpList.add("稻香");
			lineUpList.add("夜的第七章");
			lineUpList.add("听妈妈的话");
			lineUpList.add("龙卷风");
			System.out.println("初始歌曲列表："+lineUpList);
		}
		private void addMusic(ArrayList lineUpList) {
			System.out.println("输入要添加的歌曲名称:");
			String musicName =new Scanner(System.in).nextLine();
			lineUpList.add(musicName);
			System.out.println("已添加歌曲:"+musicName);
			
		}
		private void setTop(ArrayList lineUpList) {
			System.out.println("请输入要置顶的歌曲：");
			String musicName =new Scanner(System.in).nextLine();
			int position =lineUpList.indexOf(musicName);
			if (position <0) {
				System.out.println("当前列表中没有输入的歌曲!");
				
			}else {
				lineUpList.remove(musicName);
				lineUpList.add(0,musicName);
			}
			System.out.println("已将歌曲"+musicName+"置顶");
		}
		private void setBefore(ArrayList lineUpList) {
			System.out.println("请输入要置前的歌曲名称:");	
			String musicName =new Scanner(System.in).nextLine();
			int position = lineUpList.indexOf(musicName);
			if (position <0) {
				System.out.println("当前列表没有输入歌曲");
			}else if (position==0) {
				System.out.println("当前歌曲已在顶部");
			}else {
				lineUpList.remove(musicName);
				lineUpList.add(position - 1,musicName);
			}
			System.out.println("已将歌曲"+musicName+"置前一位");
		}
		private void exit1() {
			System.out.println("-------退出--------");
			System.out.println("您已退出系统");
			System.out.println(0);
		}
	}

}
